package cn.edu.javaweb.superServlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.javaweb.utils.DBUtil;
@WebServlet("/SelectCollageAdmin")
public class SelectCollageAdmin extends HttpServlet {
	DBUtil db; //声明对象 一定要赋值  否则空指针异常
	private static final long serialVersionUID = 1L;
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		db=new DBUtil(); //建创对象 搭桥配置初始化
		String sql="select *from user where ident=1 and roster=1";  //写入sql语句  0是加入黑名单
		System.out.println(sql);//打印sql语句

		
		List list = db.getList(sql);
		request.setAttribute("List", list);
		System.out.println(list); 
		//response.sendRedirect("volunteer/super/CollageAdmin.jsp");
		
		//分页
		String p = request.getParameter("page");
        int page;
        try {
            //当前页数
            page = Integer.valueOf(p);
        } catch (NumberFormatException e) {
            page = 1;
        }
		int tolist= list.size();
        int perpage = 4;
        int toall = tolist % perpage == 0 ? tolist / perpage : tolist / perpage + 1;
        int beginIndex = (page - 1) * perpage;
        int endIndex = beginIndex + perpage;
        if (endIndex > tolist)
            endIndex = tolist;
        System.out.println(tolist);
		request.setAttribute("toall", toall);
		request.setAttribute("beginIndex", beginIndex);
		request.setAttribute("endIndex", endIndex);
		request.setAttribute("page", page);
		
		
		
		request.getRequestDispatcher("volunteer/super/CollageAdmin.jsp").forward(request, response); 
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response); 
	}

}





